package com.compunit.composite.core.cx;

import com.compunit.composite.core.interfaces.cx.ICxBinding;

/**
 * <code>Binding</code> defines the implementation of
 * a pair of provider and consumer binding in a single
 * component.
 *
 * @author Yi Wang (Neakor)
 * @version Creation date: 11-07-2009 19:02 EST
 * @version Modified date: 11-12-2009 12:36 EST
 */
public class CxBinding implements ICxBinding {
	/**
	 * The <code>String</code> provider fully qualified
	 * class name.
	 */
	private String provider;
	/**
	 * The <code>String</code> consumer fully qualified
	 * class name.
	 */
	private String consumer;
	
	/**
	 * Constructor of <code>Binding</code>.
	 */
	public CxBinding() {}

	@Override
	public void setProvider(final String provider) {
		this.provider = provider;
	}

	@Override
	public void setConsumer(final String consumer) {
		this.consumer = consumer;
	}

	@Override
	public String getProvider() {
		return this.provider;
	}

	@Override
	public String getConsumer() {
		return consumer;
	}
	
	@Override
	public int hashCode() {
		return this.provider.hashCode() + this.consumer.hashCode();
	}
	
	@Override
	public boolean equals(final Object o) {
		if(o instanceof CxBinding) {
			final CxBinding given = (CxBinding)o;
			return (given.provider.equals(this.provider) && given.consumer.equals(this.consumer));
		}
		return false;
	}
	
	@Override
	public String toString() {
		final StringBuilder builder = new StringBuilder();
		builder.append("[(Provider:").append(this.provider).append("), (Consumer:").append(this.consumer).append(")]");
		return builder.toString();
	}
}
